﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Communergy.Common;

namespace Communergy.Data
{
    public class Reporter
    {
        IRepositoryFactory repositoryFactory;

        public Reporter(IRepositoryFactory repositoryFactory)
        {
           // this.unitOfWork = unitOfWork;
            this.repositoryFactory = repositoryFactory;
        }


        public Report BasicDailyReport(string meterId, DateTime dateFrom)
        {
            Report thisReport = new Report();

            var dateEnd = dateFrom.AddDays(1).AddSeconds(-1);
            using (IUnitOfWork unitOfWork = repositoryFactory.CreateUnitOfWork())
            {
                IRealtimeRepository realtimeRepository = this.repositoryFactory.CreateRealtimeRepository(unitOfWork);
                var realtimeData = realtimeRepository.Get_ElectricityRealtime(meterId, dateFrom, dateEnd);

                thisReport.RealtimeEnergyReadings.Add("RealtimeData", realtimeData);

                IHistoricRepository historicRepository = this.repositoryFactory.CreateHistoricRepository(unitOfWork);
                var hourly = historicRepository.GetHourly(meterId, dateFrom);

                thisReport.HistoricalEnergyReadings.Add("Hourly", hourly);
            }
            return thisReport;


        }
    }
}
